#include "Player.h"

void Player::createPlayerNode()
{
	this->playerNode = Node::create();

	Sprite* _avatar = Sprite::create(this->avatar);

	avatarSize = _avatar->getContentSize();

	Label* _name = Label::createWithTTF(this->account, "fonts/arial.ttf", 25);
	_name->setPosition(Vec2(0, avatarSize.height / 2));

	Label* _id = Label::createWithTTF(this->account_id, "fonts/arial.ttf", 25);
	_id->setPosition(Vec2(0, -avatarSize.height / 2));

	Label* _gender = Label::createWithTTF(this->gender, "fonts/arial.ttf", 25);

	Node* stencil = Node::create();

	Sprite* circle = Sprite::create("circle.png");

	circle->setScale(0.5);

	stencil->addChild(circle);

	ClippingNode* clippingNode = ClippingNode::create(stencil);

	clippingNode->addChild(_avatar);
	clippingNode->setAlphaThreshold(0.5);

	Sprite* boardSprite = Sprite::create();

	this->playerNode->addChild(clippingNode);
	this->playerNode->addChild(_name);
	this->playerNode->addChild(_id);
	//this->playerNode->addChild(_gender);
}

void Player::addToParent(Scene* _parent, int posIdx)
{
	vector<Vec2> posVec = { Vec2(this->avatarSize.width / 2, this->avatarSize.height / 2 + 12.5),
							Vec2(VISIBLE_SIZE.width - this->avatarSize.width / 2, VISIBLE_SIZE.height / 2 + this->avatarSize.height),
							Vec2(VISIBLE_SIZE.width / 2, VISIBLE_SIZE.height - this->avatarSize.height / 2 - 12.5),
							Vec2(this->avatarSize.width / 2, VISIBLE_SIZE.height / 2 + this->avatarSize.height) };
	if (_parent) {
		_parent->addChild(this->playerNode);
		this->playerNode->setPosition(posVec.at(posIdx));
		this->playerNode->setTag(posIdx);
	}
}

